home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Video / idct.asm < prev    next >
Encoding:
Assembly Source File  |  2000-05-06  |  26.4 KB  |  868 lines

  1. [SECTION .data]
  2. x0005000200010001      DQ 0005000200010001h
  3. x0040000000000000   DQ 40000000000000h
  4. x5a825a825a825a82    DW 5a82h, 5a82h, 5a82h, 5a82h  ; 23170
  5. x539f539f539f539f     DW 539fh, 539fh, 539fh, 539fh  ; 21407
  6. x4546454645464546    DW 4546h, 4546h, 4546h, 4546h  ; 17734
  7. x61f861f861f861f8    DW 61f8h, 61f8h, 61f8h, 61f8h  ; 25080
  8. scratch1    DQ 0
  9. scratch3    DQ 0
  10. scratch5    DQ 0
  11. scratch7    DQ 0
  12. ; for debug only
  13. x0    DQ 0
  14.  
  15. preSC  DW 16384, 22725, 21407, 19266,  16384, 12873, 8867,  4520
  16.      DW 22725, 31521, 29692, 26722,  22725, 17855, 12299, 6270
  17.      DW 21407, 29692, 27969, 25172,  21407, 16819, 11585, 5906
  18.      DW 19266, 26722, 25172, 22654,  19266, 15137, 10426, 5315
  19.      DW 16384, 22725, 21407, 19266,  16384, 12873, 8867,  4520
  20.      DW 12873, 17855, 16819, 15137,  25746, 20228, 13933, 7103
  21.      DW 17734, 24598, 23170, 20853,  17734, 13933, 9597,  4892
  22.      DW 18081, 25080, 23624, 21261,  18081, 14206, 9785,  4988
  23.  
  24.  
  25.  
  26.  
  27.  
  28. [SECTION .text]
  29.         push    ebp
  30.         lea     ecx, [preSC]
  31.  
  32.         mov     ebp, esp
  33.         push    esi
  34.  
  35.         mov     esi,  [ebp+8]           ; source
  36.         ;slot
  37.  
  38.         ; column 0: even part
  39.         ; use V4, V12, V0, V8 to produce V22..V25
  40.         movq mm0,  [ecx+8*12]         ; maybe the first mul can be done together
  41.                                         ; with the dequantization in iHuff module ?
  42.         ;slot
  43.  
  44.         pmulhw mm0,  [esi+8*12]       ; V12
  45.  
  46.         movq mm1,  [ecx+8*4]          ;slot
  47.  
  48.         pmulhw mm1,  [esi+8*4]        ; V4
  49.         ;slot
  50.  
  51.         movq mm3,  [ecx+8*0]
  52.         psraw mm0, 1                            ; t64=t66
  53.  
  54. pmulhw mm3,  [esi+8*0]        ; V0
  55. ;slot
  56.  
  57. movq mm5,  [ecx+8*8]          ; duplicate V4
  58. movq mm2, mm1                           ; added 11/1/96
  59.  
  60. pmulhw mm5,  [esi+8*8]        ; V8
  61. psubsw mm1, mm0                         ; V16
  62.  
  63. pmulhw mm1,  x5a825a825a825a82 ; 23170 ->V18
  64. paddsw mm2, mm0                          ; V17
  65.  
  66. movq mm0, mm2                           ; duplicate V17
  67. psraw mm2, 1                            ; t75=t82
  68.  
  69. psraw mm0, 2                            ; t72
  70. movq mm4, mm3                           ; duplicate V0
  71.  
  72. paddsw mm3, mm5                         ; V19
  73. psubsw mm4, mm5                         ; V20 ;mm5 free
  74.  
  75. ;moved from the block below
  76. movq mm7,  [ecx+8*10]
  77. psraw mm3, 1                            ; t74=t81
  78.  
  79. movq mm6, mm3                           ; duplicate t74=t81
  80. psraw mm4, 2                            ; t77=t79
  81.  
  82. psubsw mm1, mm0                         ; V21 ; mm0 free
  83. paddsw mm3, mm2                         ; V22
  84.  
  85. movq mm5, mm1                           ; duplicate V21
  86. paddsw mm1, mm4                         ; V23
  87.  
  88. movq  [esi+8*4], mm3          ; V22
  89. psubsw mm4, mm5                         ; V24; mm5 free
  90.  
  91. movq  [esi+8*12], mm1         ; V23
  92. psubsw mm6, mm2                         ; V25; mm2 free
  93.  
  94. movq  [esi+8*0], mm4          ; V24
  95. ;slot
  96.  
  97. ; keep mm6 alive all along the next block
  98. ;movq  [esi+8*8], mm6         ; V25
  99.  
  100. ; column 0: odd part
  101. ; use V2, V6, V10, V14 to produce V31, V39, V40, V41
  102.  
  103. ;moved above
  104. ;movq mm7,  [ecx+8*10]
  105.  
  106. pmulhw mm7,  [esi+8*10]               ; V10
  107. ;slot
  108.  
  109. movq mm0,  [ecx+8*6]
  110. ;slot
  111.  
  112. pmulhw mm0,  [esi+8*6]                ; V6
  113. ;slot
  114.  
  115. movq mm5,  [ecx+8*2]
  116. movq mm3, mm7                                   ; duplicate V10
  117.  
  118. pmulhw mm5,  [esi+8*2]                ; V2
  119. ;slot
  120.  
  121. movq mm4,  [ecx+8*14]
  122. psubsw mm7, mm0                                 ; V26
  123.  
  124. pmulhw mm4,  [esi+8*14]               ; V14
  125. paddsw mm3, mm0                                 ; V29 ; free mm0
  126.  
  127. movq mm1, mm7                                   ; duplicate V26
  128. psraw mm3, 1                                    ; t91=t94
  129.  
  130. pmulhw mm7,  x539f539f539f539f        ; V33
  131. psraw mm1, 1                                    ; t96
  132.  
  133. movq mm0, mm5                                   ; duplicate V2
  134. psraw mm4, 2                                    ; t85=t87
  135.  
  136. paddsw mm5, mm4                                 ; V27
  137. psubsw mm0, mm4                                 ; V28 ; free mm4
  138.  
  139. movq mm2, mm0                                   ; duplicate V28
  140. psraw mm5, 1                                    ; t90=t93
  141.  
  142. pmulhw mm0,  x4546454645464546        ; V35
  143. psraw mm2, 1                                    ; t97
  144.  
  145. movq mm4, mm5                                   ; duplicate t90=t93
  146. psubsw mm1, mm2                                 ; V32 ; free mm2
  147.  
  148. pmulhw mm1,  x61f861f861f861f8        ; V36
  149. psllw mm7, 1                                    ; t107
  150.  
  151. paddsw mm5, mm3                                 ; V31
  152. psubsw mm4, mm3                                 ; V30 ; free mm3
  153.  
  154. pmulhw mm4,  x5a825a825a825a82        ; V34
  155. nop ;slot
  156.  
  157. psubsw mm0, mm1                                 ; V38
  158. psubsw mm1, mm7                                 ; V37 ; free mm7
  159.  
  160. psllw mm1, 1                                    ; t114
  161. ;move from the next block
  162. movq mm3, mm6           ; duplicate V25
  163.  
  164. ;move from the next block
  165. movq mm7,  [esi+8*4]                  ; V22
  166. psllw mm0, 1                                    ; t110
  167.  
  168. psubsw mm0, mm5                                 ; V39 (mm5 still needed for next block)
  169. psllw mm4, 2                                    ; t112
  170.  
  171. ;move from the next block
  172. movq mm2,  [esi+8*12] ; V23
  173. psubsw mm4, mm0                                 ; V40
  174.  
  175. paddsw mm1, mm4                                 ; V41; free mm0
  176. ;move from the next block
  177. psllw mm2, 1                                    ; t117=t125
  178.  
  179. ; column 0: output butterfly
  180. ;move above
  181. ;movq mm3, mm6          ; duplicate V25
  182. ;movq mm7,  [esi+8*4]                 ; V22
  183. ;movq mm2,  [esi+8*12]                ; V23
  184. ;psllw mm2, 1                                   ; t117=t125
  185.  
  186. psubsw mm6, mm1                                 ; tm6
  187. paddsw mm3, mm1                                 ; tm8; free mm1
  188.  
  189. movq mm1, mm7                                   ; duplicate V22
  190. paddsw mm7, mm5                                 ; tm0
  191.  
  192. movq  [esi+8*8], mm3                  ; tm8; free mm3
  193. psubsw mm1, mm5                                 ; tm14; free mm5
  194.  
  195. movq  [esi+8*6], mm6                  ; tm6; free mm6
  196. movq mm3, mm2                                   ; duplicate t117=t125
  197.  
  198. movq mm6,  [esi+8*0]                  ; V24
  199. paddsw mm2, mm0                                 ; tm2
  200.  
  201. movq  [esi+8*0], mm7                  ; tm0; free mm7
  202. psubsw mm3, mm0                                 ; tm12; free mm0
  203.  
  204. movq  [esi+8*14], mm1                 ; tm14; free mm1
  205. psllw mm6, 1                                    ; t119=t123
  206.  
  207. movq  [esi+8*2], mm2                  ; tm2; free mm2
  208. movq mm0, mm6                                   ; duplicate t119=t123
  209.  
  210. movq  [esi+8*12], mm3                 ; tm12; free mm3
  211. paddsw mm6, mm4                                 ; tm4
  212.  
  213. ;moved from next block
  214. movq mm1,  [ecx+8*5]
  215. psubsw mm0, mm4                                 ; tm10; free mm4
  216.  
  217. ;moved from next block
  218. pmulhw mm1,  [esi+8*5]                ; V5
  219. ;slot
  220.  
  221. movq  [esi+8*4], mm6                  ; tm4; free mm6
  222. ;slot
  223.  
  224. movq  [esi+8*10], mm0                 ; tm10; free mm0
  225. ;slot
  226.  
  227. ; column 1: even part
  228. ; use V5, V13, V1, V9 to produce V56..V59
  229. ;moved to prev block
  230. ;movq mm1,  [ecx+8*5]
  231. ;pmulhw mm1,  [esi+8*5]               ; V5
  232.  
  233. movq mm7,  [ecx+8*13]
  234. psllw mm1, 1                                    ; t128=t130
  235.  
  236. pmulhw mm7,  [esi+8*13]               ; V13
  237. movq mm2, mm1                                   ; duplicate t128=t130
  238.  
  239. movq mm3,  [ecx+8*1]
  240. ;slot
  241.  
  242. pmulhw mm3,  [esi+8*1]                ; V1
  243. ;slot
  244.  
  245. movq mm5,  [ecx+8*9]
  246. psubsw mm1, mm7                                 ; V50
  247.  
  248. pmulhw mm5,  [esi+8*9]                ; V9
  249. paddsw mm2, mm7                                 ; V51
  250.  
  251. pmulhw mm1,  x5a825a825a825a82        ; 23170 ->V52
  252. movq mm6, mm2                                   ; duplicate V51
  253.  
  254. psraw mm2, 1                                    ; t138=t144
  255. movq mm4, mm3                                   ; duplicate V1
  256.  
  257. psraw mm6, 2                                    ; t136
  258. paddsw mm3, mm5                                 ; V53
  259.  
  260. psubsw mm4, mm5                                 ; V54 ;mm5 free
  261. movq mm7, mm3                                   ; duplicate V53
  262.  
  263. ;moved from next block
  264. movq mm0,  [ecx+8*11]
  265. psraw mm4, 1                                    ; t140=t142
  266.  
  267. psubsw mm1, mm6                                 ; V55 ; mm6 free
  268. paddsw mm3, mm2                                 ; V56
  269.  
  270. movq mm5, mm4                                   ; duplicate t140=t142
  271. paddsw mm4, mm1                                 ; V57
  272.  
  273. movq  [esi+8*5], mm3                  ; V56
  274. psubsw mm5, mm1                                 ; V58; mm1 free
  275.  
  276. movq  [esi+8*13], mm4                 ; V57
  277. psubsw mm7, mm2                                 ; V59; mm2 free
  278.  
  279. movq  [esi+8*9], mm5                  ; V58
  280. ;slot
  281.  
  282. ; keep mm7 alive all along the next block
  283. ;movq  [esi+8*1], mm7                 ; V59
  284.  
  285. ;moved above
  286. ;movq mm0,  [ecx+8*11]
  287.  
  288. pmulhw mm0,  [esi+8*11]               ; V11
  289. ;slot
  290.  
  291. movq mm6,  [ecx+8*7]
  292. ;slot
  293.  
  294. pmulhw mm6,  [esi+8*7]                ; V7
  295. ;slot
  296.  
  297. movq mm4,  [ecx+8*15]
  298. movq mm3, mm0                                   ; duplicate V11
  299.  
  300. pmulhw mm4,  [esi+8*15]               ; V15
  301. ;slot
  302.  
  303. movq mm5,  [ecx+8*3]
  304. psllw mm6,1                                     ; t146=t152
  305.  
  306. pmulhw mm5,  [esi+8*3]                ; V3
  307. paddsw mm0, mm6                                 ; V63
  308.  
  309. ; note that V15 computation has a correction step:
  310. ; this is a 'magic' constant that rebiases the results to be closer to the expected result
  311. ; this magic constant can be refined to reduce the error even more
  312. ; by doing the correction step in a later stage when the number is actually multiplied by 16
  313.  
  314. paddw mm4,  x0005000200010001
  315. psubsw mm3, mm6                                 ; V60 ; free mm6
  316.  
  317. psraw mm0, 1                                    ; t154=t156
  318. movq mm1, mm3                                   ; duplicate V60
  319.  
  320. pmulhw mm1,  x539f539f539f539f        ; V67
  321. movq mm6, mm5                                   ; duplicate V3
  322.  
  323. psraw mm4, 2                                    ; t148=t150
  324. ;slot
  325.  
  326. paddsw mm5, mm4                                 ; V61
  327. psubsw mm6, mm4                                 ; V62 ; free mm4
  328.  
  329. movq mm4, mm5                                   ; duplicate V61
  330. psllw mm1, 1                                    ; t169
  331.  
  332. paddsw mm5, mm0                                 ; V65 -> result
  333. psubsw mm4, mm0                                 ; V64 ; free mm0
  334.  
  335. pmulhw mm4,  x5a825a825a825a82        ; V68
  336. psraw mm3, 1                                    ; t158
  337.  
  338. psubsw mm3, mm6                                 ; V66
  339. movq mm2, mm5                                   ; duplicate V65
  340.  
  341. pmulhw mm3,  x61f861f861f861f8        ; V70
  342. psllw mm6, 1                                    ; t165
  343.  
  344. pmulhw mm6,  x4546454645464546        ; V69
  345. psraw mm2, 1                                    ; t172
  346.  
  347. ;moved from next block
  348. movq mm0,  [esi+8*5]                  ; V56
  349. psllw mm4, 1                                    ; t174
  350.  
  351. ;moved from next block
  352. psraw mm0, 1                                    ; t177=t188
  353. nop ; slot
  354.  
  355. psubsw mm6, mm3                                 ; V72
  356. psubsw mm3, mm1                                 ; V71 ; free mm1
  357.  
  358. psubsw mm6, mm2                                 ; V73 ; free mm2
  359. ;moved from next block
  360. psraw mm5, 1                                    ; t178=t189
  361.  
  362. psubsw mm4, mm6                                 ; V74
  363. ;moved from next block
  364. movq mm1, mm0                                   ; duplicate t177=t188
  365.  
  366. paddsw mm3, mm4                                 ; V75
  367. ;moved from next block
  368. paddsw mm0, mm5                                 ; tm1
  369.  
  370. ;location
  371. ;  5 - V56
  372. ; 13 - V57
  373. ;  9 - V58
  374. ;  X - V59, mm7
  375. ;  X - V65, mm5
  376. ;  X - V73, mm6
  377. ;  X - V74, mm4
  378. ;  X - V75, mm3
  379. ; free mm0, mm1 & mm2
  380. ;move above
  381. ;movq mm0,  [esi+8*5]                 ; V56
  382. ;psllw mm0, 1                                   ; t177=t188 ! new !!
  383. ;psllw mm5, 1                                   ; t178=t189 ! new !!
  384. ;movq mm1, mm0                                  ; duplicate t177=t188
  385. ;paddsw mm0, mm5                                        ; tm1
  386.  
  387. movq mm2,  [esi+8*13]                 ; V57
  388. psubsw mm1, mm5                                 ; tm15; free mm5
  389.  
  390. movq  [esi+8*1], mm0                  ; tm1; free mm0
  391. psraw mm7, 1                                    ; t182=t184 ! new !!
  392.  
  393. ;save the store as used directly in the transpose
  394. ;movq  [esi+8*15], mm1                ; tm15; free mm1
  395. movq mm5, mm7                                   ; duplicate t182=t184
  396. psubsw mm7, mm3                                 ; tm7
  397.  
  398. paddsw mm5, mm3                                 ; tm9; free mm3
  399. ;slot
  400.  
  401. movq mm0,  [esi+8*9]                  ; V58
  402. movq mm3, mm2                                   ; duplicate V57
  403.  
  404. movq  [esi+8*7], mm7                  ; tm7; free mm7
  405. psubsw mm3, mm6                                 ; tm13
  406.  
  407. paddsw mm2, mm6                                 ; tm3 ; free mm6
  408. ; moved up from the transpose
  409. movq mm7, mm3
  410.  
  411. ; moved up from the transpose
  412. punpcklwd mm3, mm1
  413. movq mm6, mm0                                   ; duplicate V58
  414.  
  415. movq  [esi+8*3], mm2                  ; tm3; free mm2
  416. paddsw mm0, mm4                                 ; tm5
  417.  
  418. psubsw mm6, mm4                                 ; tm11; free mm4
  419. ; moved up from the transpose
  420. punpckhwd mm7, mm1
  421.  
  422. movq  [esi+8*5], mm0                  ; tm5; free mm0
  423. ; moved up from the transpose
  424. movq mm2, mm5
  425.  
  426. ; transpose - M4 part
  427. ;  ---------       ---------
  428. ; | M1 | M2 |     | M1'| M3'|
  429. ;  ---------  -->  ---------
  430. ; | M3 | M4 |     | M2'| M4'|
  431. ;  ---------       ---------
  432. ; Two alternatives: use full mmword approach so the following code can be
  433. ; scheduled before the transpose is done without stores, or use the faster
  434. ; half mmword stores (when possible)
  435.  
  436. movd  dword ptr [esi+8*9+4], mm3        ; MS part of tmt9
  437. punpcklwd mm5, mm6
  438.  
  439. movd dword ptr [esi+8*13+4], mm7       ; MS part of tmt13
  440. punpckhwd mm2, mm6
  441.  
  442. movd dword ptr [esi+8*9], mm5          ; LS part of tmt9
  443. punpckhdq mm5, mm3                              ; free mm3
  444.  
  445. movd dword ptr [esi+8*13], mm2         ; LS part of tmt13
  446. punpckhdq mm2, mm7                              ; free mm7
  447.  
  448. ; moved up from the M3 transpose
  449. movq mm0,  [esi+8*8]
  450. ;slot
  451.  
  452. ; moved up from the M3 transpose
  453. movq mm1,  [esi+8*10]
  454. ; moved up from the M3 transpose
  455. movq mm3, mm0
  456.  
  457. ; shuffle the rest of the data, and write it with 2 mmword writes
  458. movq  [esi+8*11], mm5         ; tmt11
  459. ; moved up from the M3 transpose
  460. punpcklwd mm0, mm1
  461.  
  462. movq  [esi+8*15], mm2         ; tmt15
  463. ; moved up from the M3 transpose
  464. punpckhwd mm3, mm1
  465.  
  466. ; transpose - M3 part
  467.  
  468. ; moved up to previous code section
  469. ;movq mm0,  [esi+8*8]
  470. ;movq mm1,  [esi+8*10]
  471. ;movq mm3, mm0
  472. ;punpcklwd mm0, mm1
  473. ;punpckhwd mm3, mm1
  474.  
  475. movq mm6,  [esi+8*12]
  476. ;slot
  477.  
  478. movq mm4,  [esi+8*14]
  479. movq mm2, mm6
  480.  
  481. ; shuffle the data and write out the lower parts of the transposed in 4 dwords
  482. punpcklwd mm6, mm4
  483. movq mm1, mm0
  484.  
  485. punpckhdq mm1, mm6
  486. movq mm7, mm3
  487.  
  488. punpckhwd mm2, mm4                              ; free mm4
  489. ;slot
  490.  
  491. punpckldq mm0, mm6                              ; free mm6
  492. ;slot
  493.  
  494. ;moved from next block
  495. movq mm4,  [esi+8*13]                 ; tmt13
  496. punpckldq mm3, mm2
  497.  
  498. punpckhdq mm7, mm2                              ; free mm2
  499. ;moved from next block
  500. movq mm5, mm3                                   ; duplicate tmt5
  501.  
  502. ; column 1: even part (after transpose)
  503.  
  504. ;moved above
  505. ;movq mm5, mm3                                  ; duplicate tmt5
  506. ;movq mm4,  [esi+8*13]                ; tmt13
  507.  
  508. psubsw mm3, mm4                                 ; V134
  509. ;slot
  510.  
  511. pmulhw mm3,  x5a825a825a825a82        ; 23170 ->V136
  512. ;slot
  513.  
  514. movq mm6,  [esi+8*9]                  ; tmt9
  515. paddsw mm5, mm4                                 ; V135 ; mm4 free
  516.  
  517. movq mm4, mm0                                   ; duplicate tmt1
  518. paddsw mm0, mm6                                 ; V137
  519.  
  520. psubsw mm4, mm6                                 ; V138 ; mm6 free
  521. psllw mm3, 2                                    ; t290
  522. psubsw mm3, mm5                                 ; V139
  523. movq mm6, mm0                                   ; duplicate V137
  524.  
  525. paddsw mm0, mm5                                 ; V140
  526. movq mm2, mm4                                   ; duplicate V138
  527.  
  528. paddsw mm2, mm3                                 ; V141
  529. psubsw mm4, mm3                                 ; V142 ; mm3 free
  530.  
  531. movq  [esi+8*9], mm0                  ; V140
  532. psubsw mm6, mm5                                 ; V143 ; mm5 free
  533.  
  534. ;moved from next block
  535. movq mm0, [esi+8*11]                  ; tmt11
  536. ;slot
  537.  
  538. movq  [esi+8*13], mm2                 ; V141
  539. ;moved from next block
  540. movq mm2, mm0                                   ; duplicate tmt11
  541.  
  542. ; column 1: odd part (after transpose)
  543.  
  544. ;moved up to the prev block
  545. ;movq mm0, [esi+8*11]                 ; tmt11
  546. ;movq mm2, mm0                                  ; duplicate tmt11
  547.  
  548. movq mm5, [esi+8*15]                  ; tmt15
  549. psubsw mm0, mm7                                 ; V144
  550.  
  551. movq mm3, mm0                                   ; duplicate V144
  552. paddsw mm2, mm7                                 ; V147 ; free mm7
  553.  
  554. pmulhw mm0,  x539f539f539f539f        ; 21407-> V151
  555. movq mm7, mm1                                   ; duplicate tmt3
  556.  
  557. paddsw mm7, mm5                                 ; V145
  558. psubsw mm1, mm5                                 ; V146 ; free mm5
  559.  
  560. psubsw mm3, mm1                                 ; V150
  561. movq mm5, mm7                                   ; duplicate V145
  562.  
  563. pmulhw mm1,  x4546454645464546        ; 17734-> V153
  564. psubsw mm5, mm2                                 ; V148
  565.  
  566. pmulhw mm3,  x61f861f861f861f8        ; 25080-> V154
  567. psllw mm0, 2                                    ; t311
  568.  
  569. pmulhw mm5,  x5a825a825a825a82        ; 23170-> V152
  570. paddsw mm7, mm2                                 ; V149 ; free mm2
  571.  
  572. psllw mm1, 1                                    ; t313
  573. nop ; slot
  574.  
  575. ;without the nop above - freeze here for one clock
  576. ;the nop cleans the mess a little bit
  577. movq mm2, mm3                                   ; duplicate V154
  578. psubsw mm3, mm0                                 ; V155 ; free mm0
  579.  
  580. psubsw mm1, mm2                                 ; V156 ; free mm2
  581. ;moved from the next block
  582. movq mm2, mm6                                   ; duplicate V143
  583.  
  584. ;moved from the next block
  585. movq mm0, [esi+8*13]  ; V141
  586. psllw mm1, 1                                    ; t315
  587.  
  588. psubsw mm1, mm7                                 ; V157 (keep V149)
  589. psllw mm5, 2                                    ; t317
  590.  
  591. psubsw mm5, mm1                                 ; V158
  592. psllw mm3, 1                                    ; t319
  593.  
  594. paddsw mm3, mm5                                 ; V159
  595. ;slot
  596.  
  597. ; column 1: output butterfly (after transform)
  598. ;moved to the prev block
  599. ;movq mm2, mm6                                  ; duplicate V143
  600. ;movq mm0, [esi+8*13] ; V141
  601.  
  602. psubsw mm2, mm3                                 ; V163
  603. paddsw mm6, mm3                                 ; V164 ; free mm3
  604.  
  605. movq mm3, mm4                                   ; duplicate V142
  606. psubsw mm4, mm5                                 ; V165 ; free mm5
  607.  
  608. movq  scratch7, mm2                   ; out7
  609. psraw mm6, 4
  610.  
  611. psraw mm4, 4
  612. paddsw mm3, mm5                                 ; V162
  613.  
  614. movq mm2, [esi+8*9]                   ; V140
  615. movq mm5, mm0                                   ; duplicate V141
  616.  
  617. ;in order not to perculate this line up, we read [esi+8*9] very near to this location
  618. movq  [esi+8*9], mm6                  ; out9
  619. paddsw mm0, mm1                                 ; V161
  620.  
  621. movq  scratch5, mm3                   ; out5
  622. psubsw mm5, mm1                                 ; V166 ; free mm1
  623.  
  624. movq [esi+8*11], mm4                  ; out11
  625. psraw mm5, 4
  626.  
  627. movq  scratch3, mm0                   ; out3
  628. movq mm4, mm2                                   ; duplicate V140
  629.  
  630. movq [esi+8*13], mm5                  ; out13
  631. paddsw mm2, mm7                                 ; V160
  632.  
  633. ;moved from the next block
  634. movq mm0,  [esi+8*1]
  635. psubsw mm4, mm7                                 ; V167 ; free mm7
  636.  
  637. ;moved from the next block
  638. movq mm7,  [esi+8*3]
  639. psraw mm4, 4
  640.  
  641. movq  scratch1, mm2                   ; out1
  642. ;moved from the next block
  643. movq mm1, mm0
  644.  
  645. movq [esi+8*15], mm4                  ; out15
  646. ;moved from the next block
  647. punpcklwd mm0, mm7
  648.  
  649. ; transpose - M2 parts
  650. ;moved up to the prev block
  651. ;movq mm0,  [esi+8*1]
  652. ;movq mm7,  [esi+8*3]
  653. ;movq mm1, mm0
  654. ;punpcklwd mm0, mm7
  655.  
  656. movq mm5,  [esi+8*5]
  657. punpckhwd mm1, mm7
  658.  
  659. movq mm4,  [esi+8*7]
  660. movq mm3, mm5
  661.  
  662. ; shuffle the data and write out the lower parts of the trasposed in 4 dwords
  663. movd dword ptr [esi+8*8], mm0          ; LS part of tmt8
  664. punpcklwd mm5, mm4
  665.  
  666. movd dword ptr [esi+8*12], mm1                 ; LS part of tmt12
  667. punpckhwd mm3, mm4
  668.  
  669. movd dword ptr [esi+8*8+4], mm5                ; MS part of tmt8
  670. punpckhdq mm0, mm5                              ; tmt10
  671.  
  672. movd dword ptr [esi+8*12+4], mm3               ; MS part of tmt12
  673. punpckhdq mm1, mm3                              ; tmt14
  674.  
  675. ; transpose - M1 parts
  676. movq mm7,  [esi]
  677. ;slot
  678.  
  679. movq mm2,  [esi+8*2]
  680. movq mm6, mm7
  681.  
  682. movq mm5,  [esi+8*4]
  683. punpcklwd mm7, mm2
  684.  
  685. movq mm4,  [esi+8*6]
  686. punpckhwd mm6, mm2 ; free mm2
  687.  
  688. movq mm3, mm5
  689. punpcklwd mm5, mm4
  690.  
  691. punpckhwd mm3, mm4                              ; free mm4
  692. movq mm2, mm7
  693.  
  694. movq mm4, mm6
  695. punpckldq mm7, mm5                              ; tmt0
  696.  
  697. punpckhdq mm2, mm5                              ; tmt2 ; free mm5
  698. ;slot
  699.  
  700. ; shuffle the rest of the data, and write it with 2 mmword writes
  701. punpckldq mm6, mm3                              ; tmt4
  702. ;move from next block
  703. movq mm5, mm2                                   ; duplicate tmt2
  704.  
  705. punpckhdq mm4, mm3                              ; tmt6 ; free mm3
  706. ;move from next block
  707. movq mm3, mm0                                   ; duplicate tmt10
  708.  
  709. ; column 0: odd part (after transpose)
  710. ;moved up to prev block
  711. ;movq mm3, mm0                                  ; duplicate tmt10
  712. ;movq mm5, mm2                                  ; duplicate tmt2
  713.  
  714. psubsw mm0, mm4                                 ; V110
  715. paddsw mm3, mm4                                 ; V113 ; free mm4
  716.  
  717. movq mm4, mm0                                   ; duplicate V110
  718. paddsw mm2, mm1                                 ; V111
  719.  
  720. pmulhw mm0,  x539f539f539f539f        ; 21407-> V117
  721. psubsw mm5, mm1                                 ; V112 ; free mm1
  722.  
  723. psubsw mm4, mm5                                 ; V116
  724. movq mm1, mm2                                   ; duplicate V111
  725.  
  726. pmulhw mm5,  x4546454645464546        ; 17734-> V119
  727. psubsw mm2, mm3                                 ; V114
  728.  
  729. pmulhw mm4,  x61f861f861f861f8        ; 25080-> V120
  730. paddsw mm1, mm3                                 ; V115 ; free mm3
  731.  
  732. pmulhw mm2,  x5a825a825a825a82        ; 23170-> V118
  733. psllw mm0, 2                                    ; t266
  734.  
  735. movq [esi+8*0], mm1                   ; save V115
  736. psllw mm5, 1                                    ; t268
  737.  
  738. psubsw mm5, mm4                                 ; V122
  739. psubsw mm4, mm0                                 ; V121 ; free mm0
  740.  
  741. psllw mm5, 1                                    ; t270
  742. ;slot
  743.  
  744. psubsw mm5, mm1                                 ; V123 ; free mm1
  745. psllw mm2, 2                                    ; t272
  746.  
  747. psubsw mm2, mm5                                 ; V124 (keep V123)
  748. psllw mm4, 1                                    ; t274
  749.  
  750. movq [esi+8*2], mm5                   ; save V123 ; free mm5
  751. paddsw mm4, mm2                                 ; V125 (keep V124)
  752.  
  753. ; column 0: even part (after transpose)
  754. movq mm0, [esi+8*12]                  ; tmt12
  755. movq mm3, mm6                                   ; duplicate tmt4
  756.  
  757. psubsw mm6, mm0                                 ; V100
  758. paddsw mm3, mm0                                 ; V101 ; free mm0
  759.  
  760. pmulhw mm6,   x5a825a825a825a82       ; 23170 ->V102
  761. movq mm5, mm7                                   ; duplicate tmt0
  762.  
  763. movq mm1, [esi+8*8]                   ; tmt8
  764. ;slot
  765.  
  766. paddsw mm7, mm1                                 ; V103
  767. psubsw mm5, mm1                                 ; V104 ; free mm1
  768.  
  769. movq mm0, mm7                                   ; duplicate V103
  770. psllw mm6, 2                                    ; t245
  771.  
  772. paddsw mm7, mm3                                 ; V106
  773. movq mm1, mm5                                   ; duplicate V104
  774.  
  775. psubsw mm6, mm3                                 ; V105
  776. psubsw mm0, mm3                                 ; V109; free mm3
  777.  
  778. paddsw mm5, mm6                                 ; V107
  779. psubsw mm1, mm6                                 ; V108 ; free mm6
  780.  
  781. ; column 0: output butterfly (after transform)
  782. movq mm3, mm1                                   ; duplicate V108
  783. paddsw mm1, mm2                                 ; out4
  784.  
  785. psraw mm1, 4
  786. psubsw mm3, mm2                                 ; out10 ; free mm2
  787.  
  788. psraw mm3, 4
  789. movq mm6, mm0                                   ; duplicate V109
  790.  
  791. movq [esi+8*4], mm1                   ; out4 ; free mm1
  792. psubsw mm0, mm4                                 ; out6
  793.  
  794. movq [esi+8*10], mm3                  ; out10 ; free mm3
  795. psraw mm0, 4
  796.  
  797. paddsw mm6, mm4                                 ; out8 ; free mm4
  798. movq mm1, mm7                                   ; duplicate V106
  799.  
  800. movq [esi+8*6], mm0                   ; out6 ; free mm0
  801. psraw mm6, 4
  802.  
  803. movq mm4, [esi+8*0]                   ; V115
  804. ;slot
  805.  
  806. movq [esi+8*8], mm6                   ; out8 ; free mm6
  807. movq mm2, mm5   ; duplicate V107
  808.  
  809. movq mm3, [esi+8*2]                   ; V123
  810. paddsw mm7, mm4                                 ; out0
  811.  
  812. ;moved up from next block
  813. movq mm0,  scratch3
  814. psraw mm7, 4
  815.  
  816. ;moved up from next block
  817. movq mm6,  scratch5
  818. psubsw mm1, mm4                                 ; out14 ; free mm4
  819.  
  820. paddsw mm5, mm3                                 ; out2
  821. psraw mm1, 4
  822.  
  823. movq [esi], mm7                       ; out0 ; free mm7
  824. psraw mm5, 4
  825.  
  826. movq [esi+8*14], mm1                  ; out14 ; free mm1
  827. psubsw mm2, mm3                                 ; out12 ; free mm3
  828.  
  829. movq [esi+8*2], mm5                   ; out2 ; free mm5
  830. psraw mm2, 4
  831.  
  832. ;moved up to the prev block
  833. movq mm4,  scratch7
  834. ;moved up to the prev block
  835. psraw mm0, 4
  836.  
  837. movq [esi+8*12], mm2                  ; out12 ; free mm2
  838. ;moved up to the prev block
  839. psraw mm6, 4
  840.  
  841. ;move back the data to its correct place
  842. ;moved up to the prev block
  843. ;movq mm0,  scratch3
  844. ;movq mm6,  scratch5
  845. ;movq mm4,  scratch7
  846. ;psraw mm0, 4
  847. ;psraw mm6, 4
  848.  
  849. movq mm1,  scratch1
  850. psraw mm4, 4
  851.  
  852. movq  [esi+8*3], mm0          ; out3
  853. psraw mm1, 4
  854.  
  855. movq  [esi+8*5], mm6          ; out5
  856. ;slot
  857.  
  858. movq  [esi+8*7], mm4          ; out7
  859. ;slot
  860.  
  861. movq  [esi+8*1], mm1          ; out1
  862. ;slot
  863.  
  864. emms
  865.  
  866. pop esi
  867. pop ebp
  868.